// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_REP_REGISTER_ATTACHED
// * CreateDate    : 2011-12-26 11:08:53
// * Creater       : CodeSmith
// * LastChangeDate: 2011-12-26 11:08:53
// * LastChanger   : 2011-12-26 11:08:53
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESOL.Common.Entity;
using Suzsoft.Smart.Data;
using System.Data;
using ESOL.Common;

namespace ESOL.Business.Rep
{
    /// <summary>
    /// RepRegisterAttached
    /// </summary>
    public partial class RepRegisterAttachedBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objRepRegisterAttachedEntity">Entity</param>
        /// <returns>Entity</returns>
        public static RepRegisterAttachedEntity GetRepRegisterAttached(RepRegisterAttachedEntity objRepRegisterAttachedEntity)
        {
            return DataAccess.SelectSingle<RepRegisterAttachedEntity>(objRepRegisterAttachedEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objRepRegisterAttachedEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertRepRegisterAttached(RepRegisterAttachedEntity objRepRegisterAttachedEntity)
        {
            return DataAccess.Insert(objRepRegisterAttachedEntity);
        }

        public static bool InsertRepRegisterAttached(List<RepRegisterAttachedEntity> objRepRegisterAttachedEntityList)
        {
            return DataAccess.Insert(objRepRegisterAttachedEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objRepRegisterAttachedEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateRepRegisterAttached(RepRegisterAttachedEntity objRepRegisterAttachedEntity)
        {
            return DataAccess.Update(objRepRegisterAttachedEntity);
        }

        public static bool UpdateRepRegisterAttached(List<RepRegisterAttachedEntity> objRepRegisterAttachedEntityList)
        {
            return DataAccess.Update<RepRegisterAttachedEntity>(objRepRegisterAttachedEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objRepRegisterAttachedEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteRepRegisterAttached(RepRegisterAttachedEntity objRepRegisterAttachedEntity)
        {
            return DataAccess.Delete(objRepRegisterAttachedEntity);
        }

        public static bool DeleteRepRegisterAttached(List<RepRegisterAttachedEntity> objRepRegisterAttachedEntityList)
        {
            return DataAccess.Delete<RepRegisterAttachedEntity>(objRepRegisterAttachedEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetRepRegisterAttachedAll()
        {
            return DataAccess.SelectAllDataSet<RepRegisterAttachedEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<RepRegisterAttachedEntity> GetRepRegisterAttachedAllList()
        {
            return DataAccess.SelectAll<RepRegisterAttachedEntity>();
        }
        #endregion


        #region Function
        public static List<RepRegisterAttachedEntity> GetAttachedsByRegisterItemID(string RegisterItemID)
        {
            if (string.IsNullOrEmpty(RegisterItemID))
                return null;
            string Sql = @"select RRA.* from REP_REGISTER_ATTACHED RRA
                where RRA.REGISTER_ITEM_ID='" + RegisterItemID + "'";
            return DataAccess.Select<RepRegisterAttachedEntity>(Sql);
        }

        public static bool UpdateOrSave(List<RepRegisterAttachedEntity> List, RepProductRegisterEntity Entity)
        {

            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                if (Entity == null)
                    return false;
                try
                {
                    broker.BeginTransaction();
                    RepRegisterAttachedEntity temp=new RepRegisterAttachedEntity();
                    temp.RegisterId=Entity.RegisterId;
                    List<RepRegisterAttachedEntity> list_temp=DataAccess.Select<RepRegisterAttachedEntity>(temp);
                    DataAccess.Delete<RepRegisterAttachedEntity>(list_temp, broker);
                    DataAccess.Insert<RepRegisterAttachedEntity>(List,broker);
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }
        #endregion
    }


}

